<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />   
        <title>Welcome to Design Zone......</title>
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/ext-all.css" />
        <link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
        <script type="text/javascript" src="../../scripts/ext/adapter/ext-base.js">
        </script>
        <script type="text/javascript" src="../../scripts/ext/ext-all.js">
        </script>
		
		<script type="text/javascript" src="../../scripts/menu/EditableItem.js"></script>
		<script type="text/javascript" src="../../scripts/menu/RangeMenu.js"></script>
		<script type="text/javascript" src="../../scripts/grid/GridFilters.js"></script>
		<script type="text/javascript" src="../../scripts/grid/filter/Filter.js"></script>
		<script type="text/javascript" src="../../scripts/grid/filter/StringFilter.js"></script>
		<script type="text/javascript" src="../../scripts/grid/filter/ListFilter.js">
        </script>
		<script type="text/javascript" src="../../scripts/grid/RowExpander.js">
        </script>
        <script type="text/javascript" src="../../scripts/i18nMessage.js">
        </script>
        <script type="text/javascript" src="../../scripts/utils.js">
        </script>
		<script type="text/javascript" src="../../scripts/imageViewer.js"></script>
        <script type="text/javascript">
        	var armorMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.armor');
			var message = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=message');
        	var store;
            var grid;
			
			var ctArmorTypeXmlLoader = new i18nMessage('../../servlet/CodeTableServlet?name=CtArmorType');
			var ctArmor1TypeXmlLoader = new i18nMessage('../../servlet/CodeTableServlet?name=CtArmor1Type');
			var ctArmorSetXmlLoader = new i18nMessage('../../servlet/CodeTableServlet?name=CtArmorSet');
			var ctBusinessTypeXmlLoader = new i18nMessage('../../servlet/CodeTableServlet?name=CtBusinessType');
            
            var deleteCallback = function(btn){
                if (btn == 'yes') {
                    Ext.Ajax.request({
                        url: '../../servlet/BiArmorServlet?action=2&id=' + deleteId,
                        success: function(o){
                            if (o.responseText == 'success') {
                                store.reload();
                                messageTip.msg(message.get('message.tip'), message.get('message.delete.successful'));
                            }
                            else {
                                messageTip.msg(message.get('message.tip'), message.get('message.delete.unsuccessful'));
                            }
                        },
                        failure: function(o){
                            messageTip.msg(message.get('message.tip'), message.get('message.delete.failure'));
                        },
                        params: {
                            foo: 'bar'
                        }
                    });
                }
            }
			
			 Ext.onReady(function(){
                // create the Data Store
                
                
                store = new Ext.data.Store({
                    url: '../../servlet/BiArmorServlet?action=4',
                    
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'id',
                        totalRecords: 'itemTotal'
                    }, [ 
                    'id', 'index', 'reference', 'ctArmorType','ctArmor1Type','armorTypeE', 'ctArmorSet', 'ctJauge', 'armor',
                     'photo1Name', 'photo2Name', 'photo3Name', 'photo4Name', 'commentFr', 'commentCn', 'commentEn']),
                    
                    remoteSort: true
                });
                
                store.setDefaultSort('id', 'desc');
				
				var filters = new Ext.grid.GridFilters({
					  filters:[
					    {type: 'string',  dataIndex: 'reference'},
					    {type: 'string', dataIndex: 'armor'},
						{type: 'list',  dataIndex: 'ctArmorType', options: ctArmorTypeXmlLoader.getCtArray() },
						{type: 'list',  dataIndex: 'ctArmorSet', options: ctArmorSetXmlLoader.getCtArray() },
						{type: 'list',  dataIndex: 'ctArmor1Type', options: ctArmor1TypeXmlLoader.getCtArray() }
					]});
                
				var expander = new Ext.grid.RowExpander({
			        tpl : new Ext.XTemplate(
						'<p><img src="../../_temp/{photo1Name}" width="150px" style="cursor: hand;" onclick="openImageViewer(this.src);"/> &nbsp;&nbsp;&nbsp;&nbsp;<img src="../../_temp/{photo2Name}" width="150px" style="cursor: hand;" onclick="openImageViewer(this.src);"/></p><br/>',
						//'&nbsp;&nbsp;&nbsp;&nbsp;<img src="../../_temp/{photo3Name}" width="150px"/>&nbsp;&nbsp;&nbsp;&nbsp;<img src="../../_temp/{photo4Name}" width="150px"/>',
						'<br/><br/><p><b>' + message.get('message.edit.descriptionfr') + ':</b> {commentFr}</p><br/>',
						'<br/><br/><p><b>' + message.get('message.edit.descriptioncn') + ':</b> {commentCn}</p><br/>',
						'<br/><br/><p><b>' + message.get('message.edit.descriptionen') + ':</b> {commentEn}</p><br/>'
			        )
			    });
                // create the grid
                grid = new Ext.grid.GridPanel({
                    title: armorMessage.get('ui.armor.listtitle'),
                    store: store,
					stripeRows: true,
					plugins: [filters, expander],
                    height: 580,
                    columns: [expander, {
                        header: message.get('message.list.id'),
                        width: 20,
                        dataIndex: 'index',
                        sortable: false
                    }, {
                        header: message.get('message.edit.reference'),
                        width: 80,
                        dataIndex: 'reference',
                        sortable: true
                    }, {
                        header: armorMessage.get('ui.armor.type'),
                        dataIndex: 'ctArmorType',
                        sortable: true
                    }, {
                        header: '',
                        dataIndex: 'ctArmor1Type',
                        sortable: true,
                        renderer:function(value, p, record){
                        		return value + ' ' +record.data.armorTypeE
                        }
                    }, {
                        header: '',
                        dataIndex: 'ctArmorSet',
                        sortable: true
                    }, {
                        header: message.get('message.list.eidt'),
                        width: 20,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderEdit
                    },{
                        header: message.get('message.list.delete'),
                        width: 20,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderDelete
                    }],
                    viewConfig: {
                        forceFit: true
                    },
                    loadMask: true,
                    renderTo: 'biArmor',
                    bbar: new Ext.PagingToolbar({
                        pageSize: 20,
                        store: store,
                        displayInfo: true
                    })
                });
                
                var startPage = getPrarmeterValue(window.location, 'startPage');
                var start;
                if (startPage == null || startPage == '') {
                    start = 0;
                }
                else {
                    start = (startPage - 1) * 20;
                }
                store.load({
                    params: {
                        start: start,
                        limit: 20
                    }
                });
                
                function renderEdit(value, p, record){
                    return String.format('<a href="armor_edit.html?id={0}&startPage={1}" target="_self"><img src="../../images/icons/pencil.png" title="' + message.get('message.list.eidt') + '" /></a>', record.id, Math.floor((record.data.index - 1) / 20) + 1);
                }
                
                function renderDelete(value, p, record){
                    return String.format('<a href="javascript: deleteItem(deleteCallback, {0});"><img src="../../images/icons/delete.png" title="' + message.get('message.list.delete') + '"/></a>', record.id);
                }
                
            });
                    
                    
        </script>
    </head>
    <body>
        <div id="biArmor">
        </div>
    </body>
</html>
